package com.iut.base_de_donnees;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class BaseDeDonnee extends SQLiteOpenHelper
{

	// All Static variables
	// Database Version
	private static final int DATABASE_VERSION = 1;
	// Database Name
	private static final String DATABASE_NAME = "QuestRep.db";
	// Contacts table name
	private static final String TABLE_QUESTREP = "QuestionReponse";
	// Contacts Table Columns names
	private static final String KEY_ID = "id";
	private static final String KEY_QUESTION = "question";
	private static final String KEY_REPONSE_1 = "reponse_1";
	private static final String KEY_REPONSE_2 = "reponse_2";
	private static final String KEY_REPONSE_3 = "reponse_3";
	private static final String KEY_REPONSE_4 = "reponse_4";
	private static final String KEY_GOOD_REPONSE = "good_reponse";
	
	public BaseDeDonnee(Context context, String name, CursorFactory factory, int version)
	{
		super(context, name, factory, version);
	}
 
    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db)
    {
        String CREATE_QUESTREP_TABLE = "CREATE TABLE " + TABLE_QUESTREP + "("
                + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_QUESTION + " TEXT NOT NULL, "
                + KEY_REPONSE_1 + " TEXT NOT NULL, " + KEY_REPONSE_2 + " TEXT NOT NULL, " + KEY_REPONSE_3
                + " TEXT NOT NULL, " + KEY_REPONSE_4 + " TEXT NOT NULL, " + KEY_GOOD_REPONSE + " TEXT NOT NULL);";
        db.execSQL(CREATE_QUESTREP_TABLE);
    }
 
    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUESTREP);
 
        // Create tables again
        onCreate(db);
    }
}